package com.yike.user.service.impl;

import com.yike.user.entity.AgentShop;
import com.yike.user.mapper.AgentShopMapper;
import com.yike.user.service.AgentShopService;
import com.yike.user.param.AgentShopPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 代理商店铺表 服务实现类
 *
 * @author Sakura
 * @since 2024-08-26
 */
@Slf4j
@Service
public class AgentShopServiceImpl extends BaseServiceImpl<AgentShopMapper, AgentShop> implements AgentShopService {

    @Autowired
    private AgentShopMapper agentShopMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveAgentShop(AgentShop agentShop) throws Exception {
        return super.save(agentShop);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateAgentShop(AgentShop agentShop) throws Exception {
        return super.updateById(agentShop);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteAgentShop(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<AgentShop> getAgentShopPageList(AgentShopPageParam agentShopPageParam) throws Exception {
        Page<AgentShop> page = new PageInfo<>(agentShopPageParam, OrderItem.desc(getLambdaColumn(AgentShop::getCreateTime)));
        LambdaQueryWrapper<AgentShop> wrapper = new LambdaQueryWrapper<>();
        IPage<AgentShop> iPage = agentShopMapper.selectPage(page, wrapper);
        return new Paging<AgentShop>(iPage);
    }

}
